<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<script type="text/x-template" id="editnewss">
    <div id="editnews">
        <div class="content">
            <div class="my-box">
                <div class="title">
                    <span>标题<em>*</em></span>
                    <input type="text" v-model="title">
                </div>
                <div class="abstract">
                    <span>摘要</span>
                    <textarea v-model="abstract"></textarea>
                </div>
                <div class="author">
                    <span>作者<em>*</em></span>
                    <input type="text" v-model="author">
                </div>
            </div>
            <div class="kingeditor">
                <span>内容<em>*</em></span>
                <div id="editoraa"></div>
            </div>
        </div>
        <div class="submit" @click="sureEdit()">
            确认修改
        </div>
    </div>
</script>
<script>
    var bbb = {
        template: '#editnewss',
        data: function() {
            return {
                newsId: "",
                newsMsg: "",
                title: "",
                abstract: "",
                author: "",
                content: "",
                status: "",
                imgs : [],
                thisPage: ""
            }
        },
        computed : {

        },
        ready : function () {
            var thisUrl = window.location.href.split('.jsp');
            var thisaa = thisUrl[0].substr(thisUrl[0].length-4);
            this.thisPage = thisaa + ".jsp";
            $('#editoraa').summernote({
                lang: 'zh-CN',
                height: 400
            });
            $("body").on("change", ".note-image-input", function(event){
                var files = event.target.files ;
                window.tempfiles = files ;
                for(var i=0;i<files.length;i++){
                    if(files[i].size>1024*1024*5){            //改了富文本插件的3111行
                        this.danger("图片大小不能超过5M!")
                    }
                }
            }.bind(this))

        },
        methods: {   //dropdown-menu dropdown-style
            sureEdit: function() {
                var _this = this;
                var content = $('#editnews .note-editable').html();
                _this.content = content;
                if($.trim(_this.title) == "") {
                    layer.open({
                        title: '提示',
                        content: '标题不能为空!'
                    })
                } else if($.trim(_this.title).length > 100){
                    layer.open({
                        title: '提示',
                        content: '标题不能超过100个字!'
                    })
                } else if($.trim(_this.summary).length > 200) {
                    layer.open({
                        title: '提示',
                        content: '摘要不能超过200个字!'
                    })
                } else if($.trim(_this.author) == "") {
                    layer.open({
                        title: '提示',
                        content: '作者不能为空!'
                    })
                } else if($.trim(_this.author).length > 100) {
                    layer.open({
                        title: '提示',
                        content: '作者不能超过100个字!'
                    })
                } else if (/^(<p>(<br>)*|(&nbsp;\s*)*<\/p>)*$/.test(_this.content)) {
                    layer.open({
                        title: '提示',
                        content: '内容不能为空!'
                    })
                } else if($.trim(_this.content).length > 10000) {
                    layer.open({
                        title: '提示',
                        content: '内容不能超过10000字!'
                    })
                } else {
                    eeesysLoading();
                    $.ajax({
                        type: 'POST',
                        url: _this.thisPage,
                        data: {
                            act: "update_news",
                            hospital: "1070",
                            status: _this.status,
                            news_id: _this.newsId,
                            title: _this.title,
                            summary: _this.abstract,
                            author: _this.author,
                            content: _this.content,
                        },
                        success: function(res) {
                            eeesysLoadingCancel();
                            res = JSON.parse(res);
                            if(res.errcode == 0) {
//                                confirmSingle({
//                                    title: "修改成功!",
//                                    success: function() {
//                                        _this.$dispatch('showList',_this.title);
//                                    }
//                                })
                                layer.open({
                                    title: '提示',
                                    content: '修改成功!',
                                    yes: function(index, layero) {
                                        _this.$dispatch('showList',_this.title);
                                        layer.close(index);
                                    }
                                })
                            } else {
                                layer.open({
                                    title: '提示',
                                    content: res.errmsg
                                })
                            }
                        }
                    })
                }
            }
        },
        events: {
            getMsg: function(msg) {
                console.log(msg);
                this.newsMsg = msg;
                this.status = msg.data.status;
                this.newsId = msg.data.news_id;
                this.title = msg.data.title;
                this.abstract = msg.data.summary;
                this.author = msg.data.author;
                this.content = msg.data.content;   //这个属性暂时用不上，笔者不知道怎么给文本编辑器里面的div赋值，所以就用js写了赋值语句
             //   this.imgs = msg.data.img;
             //   var content2 = contentWithImgs(this.content,JSON.parse(this.imgs)) ;
             //   $('#editnews .note-editable').html(content2);


                var imgs = JSON.parse(msg.data.img) ;
                var content = msg.data.html ;
                imgs.forEach(function (item) {
                    content = content.replace(item.ref,"<img style='"+item.style+"' src='"+item.src+"'>") ;
                })
                $('#editnews .note-editable').html(content) ;
            }
        }
    }
    $('body').on('click',"#editnews .note-btn.btn.btn-default.btn-sm.dropdown-toggle[data-original-title='样式']",function() {
        $('.dropdown-menu.dropdown-style').show();
    });
    $('body').on('click',"#editnews .note-btn.btn.btn-default.btn-sm.dropdown-toggle[data-original-title='段落']",function() {
        $(this).next().show();
    });
    $('body').on('click','.dropdown-menu',function(){
        //alert(1);
        $(this).hide();
    })

</script>
<link  href="/images/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link rel="stylesheet" href="/css/jquery.selectlist.css?cache=<%=Math.random()%>">
<link rel="stylesheet" href="/css/public.css?cache=<%=Math.random()%>" >
<link rel="stylesheet" href="/css/messages_doctor_mes.css?cache=<%=Math.random()%>">

<!--富文本编辑器需要依赖以下的外部文件-->
<link href="http://cdn.gbtags.com/twitter-bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/summernote/0.8.2/summernote.css" rel="stylesheet">
<script src="/js/bootstrap.min.js"></script>
<script src="../demo/summernote.js?cache=<%=Math.random()%>"></script>
<script src="http://cdn.bootcss.com/summernote/0.7.1/lang/summernote-zh-CN.min.js"></script>
<!--end-->
<style>
    body {
        background-color: #F1F2F7!important;
    }
    a {
        color: #646464;
    }
    a:hover {
        text-decoration: none;
        color: #646464;
    }
    #editnews .my-box span {
        display: inline-block;;
        width: 60px!important;
        font-size: 18px;
    }
    #editnews .my-box em {
        color: red;
    }
    #editnews .my-box>div {
        margin-top: 30px;
    }
    #editnews .my-box input,
    #editnews .my-box textarea {
        width: 600px;
        padding: 10px;
    }
    #editnews .my-box textarea {
        vertical-align: top;
    }
    #editnews .submit {
        display: inline-block;
        padding: 6px 10px;
        font-size: 18px;
        background-color: #68cacb;
        color: #fff;
        border-radius: 5px;
        margin-left: 300px;
        cursor: pointer;
    }
    #editnews .right_cont_container {
        padding: 20px;
    }
    #editnews .kingeditor {
        width: 600px;
        margin-top: 30px;
    }
    #editnews .note-editor {
        top: -27px;
        left: 63px;
    }
</style>